#include "stdafx.h"
#include "Analyze.h"
#include <wtypes.h>
#include "..\Parser.h"

BOOL if_desc_first()
{
	SymbolStack.Pop(); // if
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stIf,0);
	Node->Child().Add(ParserAnalyze.Pop());
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL if_desc_second()
{
	SymbolStack.Pop(); // then
	NAutoPtr<CSyntaxTreeNode> Node = ParserAnalyze.Pop();
	if(Node->Type() != CSyntaxTreeNode::stIf)
	{
		ParserAnalyze.Top()->Value() |= 1 << 0; // if have stmt_list1 the lowest bit is 1
		ParserAnalyze.Top()->Child().Add(Node);
	}
	else ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL if_desc_third()
{
	SymbolStack.Pop(); // else
	NAutoPtr<CSyntaxTreeNode> Node = ParserAnalyze.Pop();
	if(Node->Type() != CSyntaxTreeNode::stIf)
	{
		ParserAnalyze.Top()->Value() |= 1 << 1; // if have stmt_list2 the second lowest bit is 1
		ParserAnalyze.Top()->Child().Add(Node);
	}
	else ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL if_desc_fourth()
{
	SymbolStack.Pop(); // if
	SymbolStack.Pop(); // end
	return TRUE;
}